package com.ideaaedi.commonspring.entity.dto;

import com.ideaaedi.commonspring.lite.ratelimiter.RateLimiter;
import lombok.Data;

import java.lang.reflect.Method;
import java.util.Objects;

/**
 * 限流信息
 *
 * @author <font size = "20" color = "#3CAA3C"><a href="https://gitee.com/JustryDeng">JustryDeng</a></font> <img src="https://gitee.com/JustryDeng/shared-files/raw/master/JustryDeng/avatar.jpg" />
 * @since 2100.10.17.LTS17
 */
@Data
public class RateLimitInfoDTO {

    /** 目标方法 */
    private Method targetMethod;

    /** 限流注解 */
    private RateLimiter rateLimiterAnno;

    /** （spel解析后的）限流器唯一标识 */
    private String rateLimiterUid;

    /** 请求是否成功获取到了临牌 */
    private boolean obtainedToken;

    public RateLimitInfoDTO(Method targetMethod, RateLimiter rateLimiterAnno, String rateLimiterUid, boolean obtainedToken) {
        Objects.requireNonNull(targetMethod, "targetMethod cannot be null.");
        Objects.requireNonNull(rateLimiterAnno, "rateLimiterAnno cannot be null.");
        Objects.requireNonNull(rateLimiterAnno, "rateLimiterAnno cannot be null.");
        Objects.requireNonNull(obtainedToken, "obtainedToken cannot be null.");
        this.targetMethod = targetMethod;
        this.rateLimiterAnno = rateLimiterAnno;
        this.obtainedToken = obtainedToken;
        this.rateLimiterUid = rateLimiterUid;
    }
}
